# 图像加法：目标图像 = 图像1 + 图像2,注：参与运算的图像大小和类型必须一致

import cv2
import numpy as np
import matplotlib.pyplot as plt

# 读取图片
img = cv2.imread("src/lena_gray.png", cv2.IMREAD_UNCHANGED)
test = img

# 1、灰度图片相加
# 方法一：Numpy加法运算,运算结果进行取模运算
result1 = img + test

# 方法二：OpenCV加法运算,运算结果是饱和运算
result2 = cv2.add(img, test)

# 显示图像
cv2.imshow("original", img)
cv2.imshow("result1_Numpy", result1)
cv2.imshow("result2_OpenCv", result2)

# 等待显示
cv2.waitKey(0)
cv2.destroyAllWindows()

# 2、彩色图片相加
# 读取图片
img = cv2.imread("src/lena.png", cv2.IMREAD_UNCHANGED)
test = img

# 方法一：Numpy加法运算
result1 = img + test

# 方法二：OpenCV加法运算
result2 = cv2.add(img, test)

# 显示图像
cv2.imshow("original", img)
cv2.imshow("result1_Numpy", result1)
cv2.imshow("result2_OpenCv", result2)

# 等待显示
cv2.waitKey(0)
cv2.destroyAllWindows()
